package com.xbongbong.paas.script.controller;

import com.xbongbong.paas.pojo.dto.DynamicMigrationDTO;
import com.xbongbong.paas.pojo.dto.PaymentSheetDataDTO;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.saas.service.DynamicMigrationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 数据迁移脚本
 *
 * @param
 * @author lzf
 * @date 2022/4/19 13:51
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/script/dynamic")
public class DynamicDataMigrationController {

    private static final Logger LOG = LoggerFactory.getLogger(DynamicDataMigrationController.class);
    @Resource
    private DynamicMigrationService dynamicMigrationService;


    /**
     * 刷动态脚本
     * date: 2022/6/21 9:01 上午
     * @Author yingjf
     * @param dynamicMigrationDTO:
     */
    @RequestMapping(value = "/migration", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String dynamicMigration(@RequestBody @Valid DynamicMigrationDTO dynamicMigrationDTO) {
        int start = DateUtil.getInt();
        LOG.info("------------------------- 动态详情数据迁移脚本 -> 开始执行 --------------------------");
        LOG.info("========================= 动态详情数据迁移脚本 执行开始时间：" + start + " ==========================");
        try {
            dynamicMigrationService.migration(dynamicMigrationDTO);
        } catch (Exception e) {
            LOG.error("脚本执行失败", e);
            return "fail";
        }
        int time = DateUtil.getInt() - start;
        LOG.info("------------------------- 动态详情数据迁移脚本 -> 执行结束  共计花费{}秒--------------------------", time);
        return "success";
    }
}
